package com.ss.android.article.common.share.helper;

import android.content.Context;
import android.text.TextUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.account.Spipe;
import com.ss.android.account.c.QZone;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.share.abs.AbsShareHelper;
import com.ss.android.article.common.share.interf.IShareArticleBean;
import com.ss.android.article.common.share.interf.IShareDataBean;
import com.ss.android.article.common.share.interf.IShareEntryItemBean;
import com.ss.android.article.common.share.interf.IShareEssayBean;
import com.ss.android.article.common.share.interf.k;
import com.ss.android.article.common.share.interf.ISharePostBean;
import com.ss.android.article.common.share.interf.IShareUpdateItemBean;
import com.ss.android.article.share.d.e;
import com.ss.android.article.share.entity.ShareAction;
import com.ss.android.article.share.entity.ShareImageBean;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.image.model.ImageUrl;
import com.ss.android.model.AbsArticle;

import java.util.Iterator;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

import inline.ShareDemo;

public class CommonQQShareHelper extends AbsShareHelper {
    public ArticleActionHelper mActionHelper;
    protected boolean isQzone;
    protected int scene;
    private Context mContext;
    private String mAppName;
    private boolean mPgcIsSelf;
    private static String TAG = "CommonQQShareHelper";

    public CommonQQShareHelper(Context arg3) {
        this.mAppName = "";
        this.mPgcIsSelf = false;
        this.isQzone = false;
        this.scene = 3;
        this.mContext = arg3;
        if(this.mContext != null) {
            this.mAppName = this.mContext.getString(com.ss.android.article.browser.R.string.app_name);
        }
    }

    public final boolean a(IShareDataBean arg13) {
        String v5_1;
        String v0_1;
        String v4;
        String v3;
        String v2_1;
        boolean v1;
        int v0 = 17;
        int v7 = 15;
        boolean v8 = false;
        String v6 = null;
        if(this.mContext == null || arg13 == null) {
            Logger.w(TAG, "parameters is null for shareQQ");
        }
        else if(!QZone.a(this.mContext)) {
            UIUtils.showImageToast(this.mContext, R.drawable.close_popup_textpage, R.string.toast_qq_not_install);
        }
        else if((arg13 instanceof IShareArticleBean)) {
            v1 = this.isQzone;
            if(this.mContext != null && arg13 != null) {
                int v2 = v1 ? v0 : v7;
                if(this.mActionHelper != null && ((arg13 instanceof AbsArticle))) {
                    this.mActionHelper.a(v2, (AbsArticle) arg13, this.mAdid);
                }

                v2_1 = ((IShareArticleBean)arg13).a("mobile_qq", "mobile_qq");
                v3 = this.mAppName;
                v4 = ((IShareArticleBean)arg13).getTitle();
                if(((IShareArticleBean)arg13).v() > 0) {
                    if(arg13 == null) {
                        v0_1 = v6;
                    }
                    else {
                        v0_1 = ImageInfo.getUrlFromImageInfo(((IShareArticleBean)arg13).getMiddleImage(), false);
                        if((android.support.design.a.isTextEmpty(v0_1)) && ((IShareArticleBean)arg13).t() != null && ((IShareArticleBean)arg13).t().size() > 0) {
                            Iterator v5 = ((IShareArticleBean)arg13).t().iterator();
                            do {
                                if(v5.hasNext()) {
                                    v0_1 = ImageInfo.getUrlFromImageInfo((ImageInfo) v5.next(), false);
                                    if(android.support.design.a.isTextEmpty(v0_1)) {
                                        continue;
                                    }
                                }

                                break;
                            }
                            while(true);
                        }

                        if(!android.support.design.a.isTextEmpty(v0_1)) {
                        }else {
                            v0_1 = ImageInfo.getUrlFromImageInfo(((IShareArticleBean) arg13).s(), false);
                        }
                    }
                    if(android.support.design.a.isTextEmpty(v0_1)) {
                        v0_1 = "http://p0.pstatp.com/medium/6399/2275149767";
                    }

                    v5_1 = v0_1;
                }
                else {
                    v5_1 = v6;
                }

                this.setArticleRespEntry(((IShareArticleBean)arg13), this.scene);
                v8 = this.a(v1, v2_1, v3, v4, v5_1, v6);
            }
        }
        else {
            if((arg13 instanceof k)) {
                v1 = this.isQzone;
                if(this.mContext == null) {
                    return v8;
                }

                if(arg13 == null) {
                    return v8;
                }

                if(android.support.design.a.isTextEmpty(((k)arg13).a())) {
                    return v8;
                }

                if(android.support.design.a.isTextEmpty(((k)arg13).getShareUrl())) {
                    return v8;
                }

                v2_1 = ((k)arg13).getShareUrl();
                v3 = "mobile_qq";
                v0_1 = v1 ? "qzone" : "mobile_qq";
                v2_1 = a(v2_1, v3, v0_1);
                v3 = this.mAppName;
                v4 = ((k)arg13).a();
                if(((k)arg13).c() <= 0 || (android.support.design.a.isTextEmpty(((k)arg13).b()))) {
                    v5_1 = v6;
                }
                else {
                    v0_1 = ImageInfo.getUrlFromImageInfo(new ImageInfo(((k)arg13).b(), v6), true);
                    if(android.support.design.a.isTextEmpty(v0_1)) {
                        v0_1 = "http://p0.pstatp.com/medium/6399/2275149767";
                    }

                    v5_1 = v0_1;
                }

                this.setForumRespEntry(this.scene);
                return this.a(v1, v2_1, v3, v4, v5_1, v6);
            }

            if((arg13 instanceof IShareUpdateItemBean)) {
                v1 = this.isQzone;
                if(this.mContext == null) {
                    return v8;
                }

                if(arg13 == null) {
                    return v8;
                }

                if(android.support.design.a.isTextEmpty(((IShareUpdateItemBean)arg13).getShareUrl())) {
                    return v8;
                }

                if(!QZone.a(this.mContext)) {
                    UIUtils.showImageToast(this.mContext, R.drawable.close_popup_textpage, R.string.toast_qq_not_install);
                    return v8;
                }

                v4 = ((IShareUpdateItemBean)arg13).e();
                v2_1 = ((IShareUpdateItemBean)arg13).getShareUrl();
                v3 = "mobile_qq";
                v0_1 = v1 ? "qzone" : "mobile_qq";
                v2_1 = a(v2_1, v3, v0_1);
                v3 = this.mContext.getString(com.ss.android.article.browser.R.string.app_name);
                if(arg13 == null) {
                    v0_1 = v6;
                }
                else {
                    if(((IShareUpdateItemBean)arg13).b() == null || ((IShareUpdateItemBean)arg13).b().size() <= 0) {
                        v0_1 = v6;
                    }
                    else {
                        List v0_2 = ImageInfo.extractImageUrlList(v6, ((ImageInfo)((IShareUpdateItemBean)arg13).b().get(0)).mUrlList);
                        if(v0_2 == null) {
                            v0_1 = v6;
                        } else if(v0_2.size() > 0) {
                            v0_1 = ((ImageUrl)v0_2.get(0)).url;
                        } else {
                            v0_1 = v6;
                        }
                    }

                    if(!android.support.design.a.isTextEmpty(v0_1)) {
                    }else {
                        v0_1 = ((IShareUpdateItemBean) arg13).c();
                    }
                }

                if(((IShareUpdateItemBean)arg13).d() <= 0 || (android.support.design.a.isTextEmpty(v0_1))) {
                    v5_1 = v6;
                }
                else {
                    v0_1 = ImageInfo.getUrlFromImageInfo(new ImageInfo(v0_1, v6), true);
                    if(android.support.design.a.isTextEmpty(v0_1)) {
                        v0_1 = "http://p0.pstatp.com/medium/6399/2275149767";
                    }

                    v5_1 = v0_1;
                }

                this.setUpdateRespEntry(((IShareUpdateItemBean)arg13), this.scene);
                return this.a(v1, v2_1, v3, v4, v5_1, v6);
            }

            if((arg13 instanceof IShareEntryItemBean)) {
                v1 = this.isQzone;
                if(arg13 == null) {
                    return v8;
                }

                boolean v0_3 = Spipe.inst().pgcMediaid == ((IShareEntryItemBean)arg13).getId() ? true : false;
                this.mPgcIsSelf = v0_3;
                v2_1 = ((IShareEntryItemBean)arg13).getShareUrl();
                v3 = this.mAppName;
                Context v10 = this.mContext;
                boolean v11 = this.mPgcIsSelf;
                if(arg13 == null) {
                    v4 = "";
                }
                else {
                    v0_1 = ((IShareEntryItemBean)arg13).getName() != null ? ((IShareEntryItemBean)arg13).getName() : v6;
                    v4 = ((IShareEntryItemBean)arg13).getDescription() != null ? ((IShareEntryItemBean)arg13).getDescription() : v6;
                    String v9 = ((IShareEntryItemBean)arg13).getShareUrl() != null ? ((IShareEntryItemBean)arg13).getShareUrl() : v6;
                    String v7_1 = v11 ? v10.getString(com.ss.android.article.browser.R.string.s5) : v10.getString(com.ss.android.article.browser.R.string.s6);
                    v4 = String.format(v7_1, v0_1, v4, v9);
                }

                if(((IShareEntryItemBean)arg13).getUseImage4QQShare() <= 0 || (android.support.design.a.isTextEmpty(((IShareEntryItemBean)arg13).getIconUrl()))) {
                    v5_1 = v6;
                }
                else {
                    v0_1 = ImageInfo.getUrlFromImageInfo(new ImageInfo(((IShareEntryItemBean)arg13).getIconUrl(), v6), true);
                    if(android.support.design.a.isTextEmpty(v0_1)) {
                        v0_1 = "http://p0.pstatp.com/medium/6399/2275149767";
                    }

                    v5_1 = v0_1;
                }

                this.setEntryItemRespEntry(((IShareEntryItemBean)arg13), this.scene);
                return this.a(v1, v2_1, v3, v4, v5_1, v6);
            }

            if((arg13 instanceof IShareEssayBean)) {
                v1 = this.isQzone;
                if(arg13 == null) {
                    return v8;
                }

                v2_1 = ((IShareEssayBean)arg13).f();
                v3 = this.mContext.getString(com.ss.android.article.browser.R.string.app_name);
                v4 = ((IShareEssayBean)arg13).d();
                if(((IShareEssayBean)arg13).c() > 0) {
                    if(arg13 == null) {
                        v5_1 = v6;
                    }
                    else {
                        v5_1 = ImageInfo.getUrlFromImageInfo(((IShareEssayBean)arg13).a(), false);
                        if(android.support.design.a.isTextEmpty(v5_1)) {
                            v5_1 = ImageInfo.getUrlFromImageInfo(((IShareEssayBean)arg13).b(), false);
                        }
                    }

                    if(!android.support.design.a.isTextEmpty(v5_1)) {
                    }else {
                        v5_1 = "http://p0.pstatp.com/medium/6399/2275149767";
                    }
                }
                else {
                    v5_1 = v6;
                }

                if(v1) {
                    v7 = v0;
                }

                if(this.mActionHelper != null && ((arg13 instanceof AbsArticle))) {
                    this.mActionHelper.a(v7, (AbsArticle) arg13);
                }

                this.setEssayRespEntry(((IShareEssayBean)arg13), this.scene);
                return this.a(v1, v2_1, v3, v4, v5_1, v6);
            }

            if((arg13 instanceof com.ss.android.article.common.share.interf.d)) {
                v1 = this.isQzone;
                if(arg13 == null) {
                    return v8;
                }

                if(this.mActionHelper != null && ((arg13 instanceof AbsArticle))) {
                    this.mActionHelper.a(v7, (AbsArticle) arg13);
                }

                return this.a(v1, ((com.ss.android.article.common.share.interf.d)arg13).b(), ((com.ss.android.article.common.share.interf.d)arg13).c(), ((com.ss.android.article.common.share.interf.d)arg13).d(), ((com.ss.android.article.common.share.interf.d)arg13).a(), ((com.ss.android.article.common.share.interf.d)arg13).e());
            }

            if((arg13 instanceof ISharePostBean)) {
                return this.a(((ISharePostBean)arg13), this.isQzone);
            }

            if(!(arg13 instanceof com.ss.android.article.common.share.interf.c)) {
                return v8;
            }

            v1 = this.isQzone;
            v2_1 = a(((com.ss.android.article.common.share.interf.c)arg13).getShareUrl(), "mobile_qq", "mobile_qq");
            v5_1 = android.support.design.a.isTextEmpty(((com.ss.android.article.common.share.interf.c)arg13).e()) ? "http://p0.pstatp.com/medium/6399/2275149767" : ((com.ss.android.article.common.share.interf.c)arg13).e();
            v8 = this.a(v1, v2_1, ((com.ss.android.article.common.share.interf.c)arg13).c(), ((com.ss.android.article.common.share.interf.c)arg13).d(), v5_1, v6);
        }

        return v8;
    }

    private static String a(String arg3, String arg4, String arg5) {
        String v0_1;
        if((android.support.design.a.isTextEmpty(arg3)) || (android.support.design.a.isTextEmpty(arg3)) || (android.support.design.a.isTextEmpty(arg3))) {
            v0_1 = "";
        }
        else {
            UrlBuilder v0 = new UrlBuilder(arg3);
            if(!android.support.design.a.isTextEmpty(arg4)) {
                if(("weixin".equals(arg4)) || ("weixin_moments".equals(arg4))) {
                    v0.addParam("wxshare_count", 1);
                }

                v0.addParam("tt_from", arg4);
            }

            if(!android.support.design.a.isTextEmpty(arg5)) {
                v0.addParam("utm_source", arg5);
            }

            v0.addParam("utm_medium", "toutiao_android");
            v0.addParam("utm_campaign", "client_share");
            v0_1 = v0.build();
        }

        return v0_1;
    }

    private boolean a(ISharePostBean arg8, boolean arg9) {
        JSONObject v0 = new JSONObject();
        if(arg8 != null) {
            try {
                v0.put("source", arg8.getId());
            }
            catch(JSONException v0_1) {
            }
        }

        String v1 = arg8.getShareUrl();
        String v3 = ShareDemo.a(this.mContext, arg8);
        String v4 = ShareDemo.a(arg8);
        String v5 = ShareDemo.b(arg8);
        String v2 = "mobile_qq";
        String v0_2 = arg9 ? "qzone" : "mobile_qq";
        v2 = a(v1, v2, v0_2);
        if(android.support.design.a.isTextEmpty(v5)) {
            v5 = "http://p0.pstatp.com/medium/6399/2275149767";
        }

        this.setPostRespEntry(arg8, this.scene);
        return this.a(arg9, v2, v3, v4, v5, null);
    }

    private boolean a(boolean arg4, String arg5, String arg6, String arg7, String arg8, String arg9) {
        if(!TextUtils.isEmpty(((CharSequence)arg8)) || (TextUtils.isEmpty(((CharSequence)arg9)))) {
            arg9 = arg8;
        }

        e v1 = new e(this.mContext);
        ShareAction v0 = arg4 ? ShareAction.qzone : ShareAction.qq;
        return v1.a(v0).b(arg7).a(arg6).c(arg5).a(new ShareImageBean(arg9, false)).a();
    }

    public final boolean doAction(Object arg2, Object[] arg3) {
        return this.a(((IShareDataBean)arg2));
    }
}

